﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace ShipborneDataTerminal.Base
{
    class sqlConnection
    {
        public MySqlConnection connection ;
        protected string server;
        protected string user;
        protected string database;
        protected string port;
        protected string password;

        public void SqlConnection(string server, string user, string password, string database, string port)
        {
            
            this.server = server;
            this.user = user;
            this.password = password;
            this.database = database;
            this.port = port;


            //this.user = "root";
            //this.server = "localhost";
            //this.password = "123456";
            //this.database = "test2";
            //this.port = "3306";
        }

        public void ConnectWithDatabase()   //establish connection with database
        {
            string connString = string.Format("server={0};user={1};database={2};port={3};password={4}", server, user, database, port, password);
            connection = new MySqlConnection(connString);
        }

        public MySqlConnection GetDatabaseConnection()
        {
            return connection;
        }

        public void OpenConnection()
        {
            SqlConnection("localhost", "root", "123456", "test3", "3306");
            ConnectWithDatabase();
            connection.Open();
        }

        public void CloseConnection()
        {
            connection.Close();
        }
    }
}
